package com.neusoft.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

//import com.neusoft.CommonUtil;
import com.neusoft.po.CommonResult;
import com.neusoft.po.Food;
import com.neusoft.service.FoodService;

//@CrossOrigin("*") // 璺ㄥ煙澶勭悊
@RefreshScope
@RestController
@RequestMapping("/FoodController")
public class FoodController {

	@Autowired
	private FoodService foodService;
	public Food processHystrix_Get(@PathVariable("id") Integer id) {
    	System.out.println("food");
        throw new RuntimeException();       
    }

 
	@Value("${eureka.instance.lease-renewal-interval-in-seconds}")
	private int renewal;
	
	@Value("${eureka.instance.lease-expiration-duration-in-seconds}")
	private int expiration;
	
	// 鏍规嵁鍟嗗缂栧彿鏌ヨ鎵�灞為鍝佷俊鎭�
	@GetMapping("/listFoodByBusinessId/{businessId}")
	public CommonResult<List> listFoodByBusinessId(@PathVariable("businessId") Integer businessId) throws Exception {
		System.out.println(renewal);
		System.out.println(expiration);
		System.out.println("!!!!!!!!!!!!!!!!!!!!!");
		List<Food> list = foodService.listFoodByBusinessId(businessId);
		return new CommonResult(200, "success(10200)", list);
	}
	
	// 根据食品编号查询食品信息
	@GetMapping("/getFoodById/{foodId}")
	public CommonResult<Food> getFoodById(
			@PathVariable("foodId") Integer foodId) throws Exception {
		Food food = foodService.getFoodById(foodId);
		return new CommonResult(200, "success（10200）", food);
	}
	
	@PostMapping("/updateFood/{foodId}/{foodPrice}")
	public CommonResult<Integer> updateFood(
			@PathVariable("foodId") Integer foodId,
			@PathVariable("foodPrice") Integer foodPrice) throws Exception {
		int result = foodService.updateFood(foodId, foodPrice);
		return new CommonResult<>(200, "success（10200）", result);
	}
}